package controlador;

import accesoDatos.DAOReportes;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;
import java.io.*;

public class reporte6_2
{
    DAOReportes objDao = new DAOReportes();
    Object[][] res1 = objDao.getDatos6_2();
    Object[][] res2 = objDao.getCount6_2();

    public void reporte6_2() throws Exception
    {
        Document document=new Document();
        PdfWriter.getInstance(document,new FileOutputStream("reporte6_2.pdf"));
        document.open();
        PdfPTable table=new PdfPTable(2);
        PdfPCell cell = new PdfPCell (new Paragraph ("Las 5 franjas horarias de más tráfico en la Biblioteca para Descargas"));
        cell.setBorderColor(BaseColor.WHITE);
        cell.setColspan (2);
        cell.setHorizontalAlignment (Element.ALIGN_CENTER);
        cell.setPadding (12.0f);
        table.addCell (cell);
        cell = new PdfPCell (new Paragraph ("Hora"));
        cell.setHorizontalAlignment (Element.ALIGN_CENTER);
        cell.setBorderColor(BaseColor.WHITE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setPadding (6.0f);
        table.addCell (cell);
        cell = new PdfPCell (new Paragraph ("Número de descargas hechas"));
        cell.setHorizontalAlignment (Element.ALIGN_CENTER);
        cell.setBorderColor(BaseColor.WHITE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setPadding (6.0f);
        table.addCell (cell);

        String res = res2[0][0].toString();
        int row = Integer.parseInt(res);
        int cont=0;

        for(int i=0;i<row;i++)
        {
            if(cont<5)
            {
                for(int j=0;j<2;j++)
                {
                    String cel = res1[i][j].toString();
                    cell = new PdfPCell(new Paragraph(cel));
                    cell.setBorderColor(BaseColor.WHITE);
                    if(cont%2==0)
                        cell.setBackgroundColor(BaseColor.GRAY);
                    else
                        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
                    table.addCell(cell);
                }
                cont++;
            }
        }

        Image image = Image.getInstance ("imagen.jpg");
        document.add(image);
        document.add(table);
        document.close();
    }
}